import document from '@ohos.document';

export default {
    data: {
        leftWidth: 0,
        rightWidth: 0,
        startX:'',
        startY:''
    },
    props: {
        leftBg: {
            default: 'white'
        },
        rightBg: {
            default: 'green'
        },
        width: {
            default: '0'
        },
        height: {
            default: '0'
        }
    },
    onInit() {
        this.rightWidth = this.width

    },
    onShow() {
    },
    onReady() {
    },
    touchStart(e){
        this.startX = e['touches']['0'].globalX
        this.startY = e['touches']['0'].globalY
    },
    touchMove(e) {
        let globalX = e['touches']['0'].globalX
        let globalY = e['touches']['0'].globalY
        let transX = Math.abs(Number(this.startX) - Number(globalX))
        let transY = Math.abs(Number(this.startY) - Number(globalY))

        if(transX < 50){
            return
        }

        this.leftWidth = globalX
        this.rightWidth = Number(this.width) - globalX

    },
    touchEnd(e) {
        let globalX = e['changedTouches']['0'].globalX
        let globalY = e['changedTouches']['0'].globalY

        let transX = Math.abs(Number(this.startX) - Number(globalX))
        let transY = Math.abs(Number(this.startY) - Number(globalY))

        if(transX < 50){
            return
        }
        if(globalX >= Number(this.width) / 2) {
            let num = 0;
            let timer = setInterval(() => {
                num += 7.5
                this.leftWidth = num + Number(globalX)
                this.rightWidth = Number(this.width) - Number(this.leftWidth)
                if (this.leftWidth >= this.width) {
                    this.leftWidth = this.width
                    this.rightWidth = 0
                    num = 0
                    clearInterval(timer)
                }
            }, 1)
        } else {
            let num1 = 0;
            let timer1 = setInterval(() => {
                num1 += 7.5
                this.rightWidth = Number(this.width) - Number(globalX) + num1
                this.leftWidth = Number(this.width) - Number(this.rightWidth)
                if (this.rightWidth >= this.width) {
                    this.rightWidth = this.width
                    this.leftWidth = 0
                    num1 = 0
                    clearInterval(timer1)
                }
            }, 1)
        }
    },
}